package com.example.bookkeep.Utils;

import android.content.Context;
import android.content.SharedPreferences;

public class AuthUtil {
    private static final String PREF_NAME = "auth";

    public static void saveAuth(Context context, String token, int userId) {
        SharedPreferences sp = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit()
                .putString("token", token)
                .putInt("userId", userId)
                .apply();
    }

    public static String getToken(Context context) {
        return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
                .getString("token", null);
    }

    public static int getUserId(Context context) {
        return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
                .getInt("userId", -1);
    }

    public static void clearAuth(Context context) {
        context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit().clear().apply();
    }
}
